function useMockData() {
    Mock.mock("/api/admin/menu", option => new CommonMock().getMenus(option))
}

/**
 * Common 模拟数据
 * 使用：
 * import AdminMock from './AdminMock'
 * Mock.mock("/api/admin/menu", (option) => { return AdminMock.getMenuData(option) })
 * Mock.mock("/api/admin/main", (option) => { return AdminMock.getMainData(option) })
 */
class CommonMock {
    /**
     * 返回菜单列表数据
     */
    static getMenus(option) {
        let param = this.parseOption(option);
        console.log('[通用模拟数据] 显示资源列表 param=', param, '&option=', option);
        let data = [
            {
                id: 10,
                title: "控制面板",
                url: "",
                children: [
                    { id: 11, title: "运营统计", url: "/index/index" },
                ],
            },
            {
                id: 20,
                title: "会员管理",
                url: "",
                children: [
                    { id: 21, title: "会员管理", url: "/members/index" },
                    { id: 22, title: "会员等级-", url: "/member-levels/index" },
                ],
            },
            {
                id: 30,
                title: "系统设置",
                url: "",
                children: [
                    { id: 31, title: "网站设置", url: "/sys-configs/setting" },
                    { id: 32, title: "字典数据-", url: "/sys-dicts/index" },
                    { id: 33, title: "配置管理-", url: "/sys-configs/index" },
                    { id: 34, title: "通知公告", url: "/sys-notices/index" },
                ],
            },
            {
                id: 40,
                title: "权限管理",
                url: "",
                children: [
                    { id: 41, title: "管理员管理", url: "/auth-admins/index" },
                    { id: 42, title: "角色管理", url: "/auth-groups/index" },
                    { id: 43, title: "菜单管理", url: "/auth-rules/index" },
                    { id: 44, title: "岗位管理-", url: "/auth-jobs/index" },
                    { id: 45, title: "部门管理-", url: "/auth-departments/index" },
                ],
            },
        ];
        return this.stdMessage(param._success, '没有数据', data);
    }

    /**
     * 返回运营统计数据
     */
    static getMainData() {
        let param = this.parseOption(option);
        console.log('[通用模拟数据] 显示资源列表 param=', param, '&option=', option);
        let data = {
            stat_data: {
                zongzc: 354,
                benyuezc: 211,
                zuorizc: 4,
                jinrizc: 2,
                leijiczje: 1290,
                leijiczrs: 16,
                leijiczarpu: 81,
                benyueczje: 1090,
                benyueczrs: 12,
                benyueczarpu: 91,
                zuoriczje: 100,
                zuoriczrs: 1,
                zuoriczarpu: 100,
                jinriczje: 20,
                jinriczrs: 1,
                jinriczarpu: 20,
                zuorikh: 28,
                zuorixh: 498,
                jinrikh: 2,
                jinrixh: 13,
            },
        }
        data.yuefenzctj_data = {
            1: 2, 2: 2, 3: 16, 4: 9, 5: 2, 6: 2, 7: 0, 8: 44, 9: 20, 10: 37,
            11: 10, 12: 7, 13: 19, 14: 0, 15: 5, 16: 0, 17: 2, 18: 2, 19: 20, 20: 6,
            21: 4, 22: 2, 23: 0, 24: 0, 25: 0, 26: 0, 27: 0, 28: 0, 29: 0, 30: 0,
            31: 0,
        }
        data.yuefencztj_data = {
            1: 0, 2: 20, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 390, 9: 0, 10: 200,
            11: 20, 12: 20, 13: 0, 14: 20, 15: 0, 16: 0, 17: 0, 18: 0, 19: 0, 20: 300,
            21: 100, 22: 20, 23: 0, 24: 0, 25: 0, 26: 0, 27: 0, 28: 0, 29: 0, 30: 0,
            31: 0,
        }
        return this.stdMessage(param._success, '没有数据', data, status);
    }
    getDemoTjData() {
        let data = {};
        for (let i = 1; i <= 31; i++) {
            data[i] = Math.ceil(Math.random() * 1000);
        }
        return data;
    }

    getRandomStatus() {
        return Math.random() > 0.5 ? 1 : 0;
    }

    /**
     * 解析参数
     * option= {url:'/api/read?id=1', type:'GET', data:null}
     * @param {Object} option 
     * @returns
     */
    parseOption(option) {
        let param = {}
        if (option.url.indexOf('?') > -1) {
            new URLSearchParams(option.url.substring(option.url.indexOf('?') + 1)).forEach((v, k) => {
                param[k] = v;
            })
        }
        if (option.body) {
            if (option.body instanceof FormData) {
                option.body.forEach((v, k) => {
                    param[k] = v;
                })
            } else {
                param = JSON.parse(option.body);
            }
        }
        // 可以通过传参 _success 来控制返回消息的成功状态。默认返回成功消息。
        if (typeof (param._success) != 'boolean') {
            param._success = true; // Mock.mock('@boolean')
        }
        return param;
    }

    /**
     * 返回标准消息对象
     * @param {Boolean} success 
     * @param {String} message 
     * @param {Any} data 
     * @param {Number} code 
     * @returns 
     */
    stdMessage(success, message, data = '', code = 0) {
        return { success, message, data, code, }
    }
}
